
<template>
  <ex_super_dialog_form ref="reportDialog" v-bind="report_dialog" v-on="$listeners" @afterSubmitSuccess="submit">
  </ex_super_dialog_form>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      receiptIdList:[],
      report_dialog: {
        customClass: "dialog_auto",
        submitDataHandle: (data) => {
          const { attachedList, ...other } = data;
          if (attachedList) {
            if (this.isMainSystem || this.isWmsSystem) {
              other.anomalyAttachedList = attachedList;
            } else if (this.isTmsSystem) {
              other.attachedDTOList = attachedList;
            }
          }
          return other;
        },
        form: {
          itemClass: "form_item_default",
          inputClass: "form_input_default",
          formClass: "form_default_col2 flex_row_wrap",
          default: {},
          model: [
            // {
            //   key: "agentId",
            //   label: "label_tms_receipt_task_number",
            //   render: (h, { data }) => h('span', {}, data.agentId)
            // },
            {
              key: "customerName",
              label: "label_customer_name",
              render: (h, { data }) => h('span', {}, data.customerName)
            },
            {
              key:'carrierNameList',
              label: "label_receipt_carrier",
              render: (h, { data }) => h('span', {},data.carrierNameList)
            },
            {
              label: "label_order_count",
              render: (h, { data }) => h('span', {},data.orderNum)
            },
            {
              label: "label_receipt_waybill_count",
              render: (h, { data }) => h('span', {},data.tmsOrderNum)
            },
            {
              label: "label_total_box_count",
              render: (h, { data }) => h('span', {}, data.totalBoxCount)
            },
            {
              label: "label_total_sku_count",
              render: (h, { data }) => h('span', {}, data.totalQuantity)
            },
            {
              key: "tmsReceiptRecoveryEnum",
              label: "label_receipt_recycle_type",
              type: "select",
              attrs: {
                enum: "TmsReceiptRecoveryEnum",
              },
            },
            {
              if:(data)=>data.tmsReceiptRecoveryEnum=== 'FACE_TO_FACE',
              key: "recoveryUsername",
              label: "label_repo_person",
            },
            {
              if:(data)=>data.tmsReceiptRecoveryEnum=== 'EXPRESS',
              key: "recoveryExpressNo",
              label: "label_tms_ems_no",
            },

            {
              key: "recoveryNum",
              label: "label_receipt_recycle_num",
              attrs: {type:"number", maxlength: 9, "show-word-limit": true },
            },
          ],
          rules: {
            tmsReceiptRecoveryEnum: {
              required: true,
              message: this.$tt("tip_can_no_empty"),
              trigger: "blur",
            },
            recoveryUsername: {
              required: true,
              message: this.$tt("tip_can_no_empty"),
              trigger: "blur",
            },
            recoveryNum: {
              required: true,
              message: this.$tt("tip_can_no_empty"),
              trigger: "blur",
            },
            recoveryExpressNo: {
              required: true,
              message: this.$tt("tip_can_no_empty"),
              trigger: "blur",
            },
          },
        },
      },

    }
  },

  methods: {
    show(rows) {

      this.receiptIdList = []
      const obj = {
        customerName:'',
        carrierNameList:[],
        totalBoxCount:0,
        totalQuantity:0,
        // 后面两个字段无意义，产品要求先显示
        orderNum:rows.length,
        tmsOrderNum:rows.length
      }
      rows.forEach(item=>{
        this.receiptIdList.push(item.id)
        obj.customerName = item.customerName
        obj.carrierNameList.push(...item.carrierNameList)
        obj.totalBoxCount+=item.totalBoxCount
        obj.totalQuantity+=item.totalQuantity
      })
      obj.carrierNameList = obj.carrierNameList.join(',')
      const option = Object.assign(
        {
          title: this.$t("label_tms_receipt_receipt_recycle"),
          // submitUrl: this.$url["tms/BaseAnomalyReport"],
          // detailUrl:this.$url["wms/BaseAnomalyDetail"],
        },
        {
          data: obj,
          onlySetData: true,
          submitCall:(data,formData,submitCallResult)=>{
            submitCallResult(true,true,false)
          },
        }
      );


      this["$refs"]["reportDialog"].showNew(option);
    },
    submit(data) {
      this.$ajax({
        url: "/tms-api/task/TmsOrderReceiptInfoRpc/recoveryReceiptInfo.json",
        method: 'post',
        type: 'json',
        data: {
            "receiptIdList":this.receiptIdList,//数组
            "tmsReceiptRecoveryEnum":data.tmsReceiptRecoveryEnum,//回收方式
            "recoveryNum":data.recoveryNum,//回收数量
            "recoveryUsername":data.recoveryUsername,//回收人
            "recoveryExpressNo":data.recoveryExpressNo//回收邮寄单号
        },
        success: (res) => {
          this.$message.success(this.$t("label_receipt_tip_submit_recycle"))
          this.$emit('submitSuccess')
        }
      })

    }
  }
}
</script>
